

import 'package:bike_ride/common/util/account_manager.dart';
import 'package:bike_ride/common/util/hysize_fit.dart';
import 'package:bike_ride/generated/l10n.dart';
import 'package:bike_ride/router/navigator_util.dart';
import 'package:bike_ride/router/routers.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

/// 用户协议
class ProtocolCheck extends StatelessWidget {
  final bool current;
  final Function(bool) onChanged;

  const ProtocolCheck({super.key, required this.current, required this.onChanged});

  @override
  Widget build(BuildContext context) {
    final tapServiceGestureRecognizer = TapGestureRecognizer();
    final tapPrivateGestureRecognizer = TapGestureRecognizer();

    return GestureDetector(
      onTap: () {
        onChanged(!current);
      },
      child: Row(
        children: [
          Icon(
            current ? Icons.check_circle : Icons.radio_button_unchecked,
            color: current
                ? Theme.of(context).colorScheme.primary
                : Colors.black.withAlpha(45),
            size: 18,
          ),
          SizedBox(
            width: 6.rpx,
          ),
          RichText(
            text: TextSpan(
              children: <InlineSpan>[
                TextSpan(text: S.current.agreeProtocol),
                TextSpan(
                  text: '《${S.current.agreeProtocolA}》',
                  style: TextStyle(
                    color: Theme.of(context).colorScheme.primary,
                  ),
                  recognizer: tapServiceGestureRecognizer
                    ..onTap = () {
                      NavigatorUtil.push(context, Routers.webViewPage,arguments: {
                        'url': AccountManager.useProtocolUrl,
                      });
                    },
                ),
                TextSpan(text: S.current.agreeProtocol_),
                TextSpan(
                  text: '《${S.current.agreeProtocolB}》',
                  style: TextStyle(
                    color: Theme.of(context).colorScheme.primary,
                  ),
                  recognizer: tapPrivateGestureRecognizer
                    ..onTap = () {
                      NavigatorUtil.push(context, Routers.webViewPage,arguments: {
                        'url': AccountManager.privacyProtocolUrl,
                      });
                    },
                )
              ],
              style: TextStyle(
                color: Colors.black.withAlpha(45),
                fontSize: 24.rpx,
                height: 1.3,
                fontWeight: FontWeight.w500,
              ),
            ),
          ),
        ],
      ),
    );
  }
}